package com.java.demo.model;

/**
 * 桥接模式
 *
 * @auther zhangwj
 * @date 2020/12/4 下午5:00
 */
public class BridgePattern {

    public static void main(String[] args) {
        Graph round = new Round();
        Colour yellow = new Yellow(round);
        yellow.colour();
    }
}

interface Graph {

    void graph();
}

class Round implements Graph{

    @Override
    public void graph() {
        System.out.println("我是圆形");
    }
}

class Square implements Graph{

    @Override
    public void graph() {
        System.out.println("我是方形");
    }
}

abstract class Colour{
    protected Graph graph;
    protected Colour(Graph graph){
        this.graph = graph;
    }

    abstract void colour();
}

class Yellow extends Colour{

    protected Yellow(Graph graph) {
        super(graph);
    }

    @Override
    public void colour() {
        graph.graph();
        System.out.println("黄色");
    }
}

class Red extends Colour{

    protected Red(Graph graph) {
        super(graph);
    }

    @Override
    public void colour() {
        graph.graph();
        System.out.println("红色");
    }
}

